﻿using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

/// <summary>
/// Summary description for CustomBRL
/// </summary>
/// 
namespace hou_elearning.Custom
{
    public class NguoidungCustomBRL : SqlProvider<NguoidungEntity>
    {
        public NguoidungCustomBRL()
        {
            
        }

        //protected static void InitReader()
        //{
        //    getFromReader = delegate(SqlDataReader dr)
        //    {
        //        NguoidungEntity entity = new NguoidungEntity();
        //        entity.PK_iNguoidungID = Int64.Parse("0" + dr["PK_iNguoidungID"].ToString());
        //        entity.sTendangnhap = dr["sTendangnhap"].ToString();
        //        entity.sMatkhau = dr["sMatkhau"].ToString();
        //        entity.sHoten = dr["sHoten"].ToString();
        //        entity.sEmail = dr["sEmail"].ToString();
        //        entity.sSodienthoai = dr["sSodienthoai"].ToString();
        //        entity.dNgaysinh = String.IsNullOrEmpty(dr["dNgaysinh"].ToString()) ? DateTime.Now : DateTime.Parse(dr["dNgaysinh"].ToString());
        //        entity.bGioitinh = String.IsNullOrEmpty(dr["bGioitinh"].ToString()) ? false : Boolean.Parse(dr["bGioitinh"].ToString());
        //        entity.sDiachi = dr["sDiachi"].ToString();
        //        entity.sGhichu = dr["sGhichu"].ToString();
        //        try
        //        {
        //            entity.bAnhthe = (byte[])(dr["bAnhthe"]);
        //        }
        //        catch { }
        //        entity.iDanhgia = int.Parse("0" + dr["iDanhgia"].ToString());
        //        return entity;
        //    };
        //}

             private static SqlParameter[] initParams(NguoidungEntity entity)
        {
            SqlParameter[] p = new SqlParameter[7];
			p[0] = new SqlParameter("@PK_iNguoidungID", entity.PK_iNguoidungID);						
			p[1] = new SqlParameter("@sHoten", entity.sHoten);			
			p[2] = new SqlParameter("@sSodienthoai", entity.sSodienthoai);
			p[3] = new SqlParameter("@dNgaysinh", entity.dNgaysinh);
			p[4] = new SqlParameter("@bGioitinh", entity.bGioitinh);
			p[5] = new SqlParameter("@sDiachi", entity.sDiachi);
            p[6] = new SqlParameter("@sGhichu", entity.sGhichu);
			//p[10] = new SqlParameter("@bAnhthe", entity.bAnhthe);
            //p[11] = new SqlParameter("@iDanhgia", entity.iDanhgia);
            
            return p;
        }
        
        public static bool bCheckDupByTendangnhap(String sTendangnhap)
        {
            string cmdName = "spNguoidung_GetByTendangnhap";
            SqlParameter p = new SqlParameter("sTendangnhap", sTendangnhap);
            NguoidungEntity entity = GetOne(cmdName,p);
            if (entity != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public static bool bCheckDupByEmail(String sEmail)
        {
            string cmdName = "spNguoidung_GetByEmail";
            SqlParameter p = new SqlParameter("@sEmail", sEmail);
            NguoidungEntity entity = GetOne(cmdName, p);
            if (entity != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public static bool CustomEdit(NguoidungEntity entity)
        {
            string cmdName = "spNguoidung_CustomUpdate";
            return Run(cmdName, false, initParams(entity)) > 0;
        }
    }
}